$(function () {
    $.ajax({
        url:  "../admin/getBlogWithType",
        type: "GET",
        success: function (data) {
            for (let i = 0; i < data.length; i++) {
                $("#tbody").append("<tr>\n" +
                    "    <td style='width: 100px'>" + (i + 1) + "</td>\n" +
                    "    <td>" + data[i].id + "</td>\n" +
                    "    <td>" + data[i].title + "</td>\n" +
                    "    <td style='height: 20px;overflow: hidden;text-overflow: ellipsis; white-space: nowrap;'>" + data[i].introduction + "</td>\n" +
                    "    <td>" + formatDate(data[i].createTime) + "</td>\n" +
                    "    <td>" + data[i].blogType.typeName + "</td>\n" + "</tr>")
            }
        }
    })
    $.ajax({
        url: "../admin/queryUserNum",
        type: "GET",
        success: function (data) {
            $("#userNum").text(data);
        }
    })
    $.ajax({
        url: "../admin/blogNum",
        type: "GET",
        success: function (data) {
            $("#blogNum").text(data);
        }
    })


})

//时间戳转换方法    date:时间戳数字
function formatDate(date) {
    var date = new Date(date);
    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return YY + MM + DD + " " + hh + mm + ss;
}

// <tr>
//     <td>1</td>
//     <td>设计新主题</td>
//     <td>10/02/2019</td>
//     <td>12/05/2019</td>
//     <td><span class="label label-warning">待定</span></td>
//     <td>
//         <div class="progress progress-striped progress-sm">
//             <div class="progress-bar progress-bar-warning" style="width: 45%;"></div>
//         </div>
//     </td>
// </tr>